<template>
  <div class="check-box">
    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
    <el-checkbox-group v-model="houDelVO[configItem.key]" @change="handleCheckedCitiesChange">
      <el-checkbox v-for="item in configItem.options" :label="item" :key="item">{{
        configItem.format ? configItem.format(item) : item
      }}</el-checkbox>
    </el-checkbox-group>
  </div>
</template>
<script>
import { configHouse } from '@/config/house/houseDetailConfig';

const checkboxOptions = configHouse.find((v) => v.isCheckbox).options;

export default {
  name: 'CheckBox',
  components: {},
  props: {
    houDelVO: Object,
    configItem: Object,
  },
  data() {
    return {
      isIndeterminate: false,
      checkAll: false,
    };
  },
  created() {},
  mounted() {},
  watch: { },
  computed: {},
  methods: {
    handleCheckAllChange(val) {
      this.houDelVO.matchingFacilitiesList = val ? checkboxOptions : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === checkboxOptions.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < checkboxOptions.length;
    },
  },
};
</script>
<style scoped>
.check-box{
  padding-left: 110px;
}
</style>
